<template>
	<view>
		<view class="header">
			<image src="../../../static/icons/arrl.png" mode=""@tap="back"></image>
			<text>乐居</text>
		</view>
		<view class="buy">
			<view class="title">等待支付</view>
			<view class="site" @tap="jumpSite">
				
				<view v-if="siteInfo !=false">
					<view>姓名:{{siteInfo.name}} 电话号码: {{siteInfo.phoneNumber}}</view>
					<view>收货地址: {{siteInfo.province}}-{{siteInfo.city}}-{{siteInfo.region}}{{siteInfo.detailAddress}}</view>
				</view>
				<view v-else>去选择收货地址</view>
			</view>
			<view class="content">
				<view class="head">
					<text>订单编号: {{data[0].orderSn}}</text>
					<text>等待支付</text>
				</view>
				<view class="main"  v-for="(item2,index) in data" :key="index">
					<view class="left">
						<image :src="item2.productPic" mode=""></image>
					</view>
					<view class="right">
						<view>{{item2.productName}} ¥{{item2.productPrice}}元</view>
						<view>
							<text>编号:</text>
							<text>x {{item2.productQuantity}}</text>
						</view>
						<view>
							<view>规格:</view>
							<view v-for="(ele,index) in item2.productAttr" :key="index">
								{{ele.key}}: {{ele.value}}
							</view>
						</view>
					</view>
				</view>
				<view class="bottom">
					合计: {{total}}元
				</view>
				<view class="payment">
					<view class="btn" @tap="jumpThePayment">确认付款</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getPreOrderById } from "../../../api/home/order.js"
	export default {
		data() {
			return {
				data:[],
				siteInfo:null,
				orderId:""
			};
		},
		computed:{
			total() {
				return this.data.reduce((result,current)=>{
					return result + current.productQuantity * current.productPrice
				},0)
			}
		},
		methods:{
			back() {
				var len = getCurrentPages().length
				if (len > 1) {
					uni.navigateBack({
						delta:1
					})
				} else {
					uni.switchTab({
						url:"/pages/home/home"
					})
				}
			},
			jumpSite() {
				uni.navigateTo({
					url:`/pages/user/site/site?isShow=${true}`
				})
			},
			jumpThePayment() {
				if (this.siteInfo !=false) {
					uni.navigateTo({
						url:`/pages/home/buy/thePayment/thePayment?id=${this.orderId}`
					})
				} else {
					uni.showToast({
						title:"请选择地址",
						icon:"none"
					})
				}
			}
		},
		onLoad(options) {
			console.log(options)
			this.orderId = options.id
			getPreOrderById(options.id).then(res=>{
				this.data = res.data.orderItems
				this.data.forEach(el=>{
					el.productAttr = JSON.parse(el.productAttr)
				})
				// this.data.productAttr = JSON.parse(this.data.productAttr)
			})
		},
		onShow() {
			this.siteInfo = uni.getStorageSync("siteInfo")
		}
	}
</script>

<style lang="scss" scoped>
.header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #354e44;
	height: 60rpx;
	padding: 14rpx 6rpx;
	image {
		position: absolute;
		left: 4rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
	}
	text {
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: bolder;
	}
}
.buy {
	color: #494949;
	.title {
		height: 80rpx;
		font-size: 36rpx;
		line-height: 80rpx;
		border-bottom: 1px solid #ccc;
		margin: 0 60rpx;
	}
	.site {
		padding: 30rpx 0;
		font-size: 28rpx;
		border-bottom: 1px solid #ccc;
		margin: 0 60rpx;
	}
	.content {
		width: 600rpx;
		padding: 36rpx;
		font-size: 24rpx;
		background-color: #FFFFFF;
		border-radius: 24rpx;
		color: #3e3e3e;
		margin: 30rpx auto;
		.head {
			display: flex;
			justify-content: space-between;
			width: 100%;
			padding-bottom: 30rpx;
			border-bottom: 1px solid #f1ece7;
		}
		.main {
			display: flex;
			justify-content: space-between;
			padding: 30rpx 0;
			border-bottom: 1px solid #f1ece7;
			.left {
				width: 162rpx;
				height: 162rpx;
				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
			.right {
				>view {
					font-size: 24rpx;
					color: #8d8d8d;
					&:nth-child(1) {
						font-size: 26rpx;
						color: #3E3E3E;
						line-height: 74rpx;
					}
					&:nth-child(2) {
						display: flex;
						justify-content: space-between;
					}
					&:nth-child(3) {
						display: flex;
						view {
							margin-right: 8rpx;
						}
					}
				}
			}
		}
		.bottom {
			text-align: right;
			font-size: 26rpx;
			color: #3E3E3E;
			margin-top: 14rpx;
		}
		.payment {
			display: flex;
			justify-content: flex-end;
			margin-top: 20rpx;
			.btn {
				width: 128rpx;
				height: 54rpx;
				text-align: center;
				font-size: 26rpx;
				color: #2d4f43;
				border: 1px solid #2d4f43;
				border-radius: 10rpx;
				line-height: 50rpx;
			}
		}
	}
}
</style>
